package com.example.pubsearch;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.pubsearch.db.MySQLiteHelper;
import com.example.pubsearch.db.Pub;

public class DetailActivity extends Activity {

	private Pub pub;

	private TextView name;

	private TextView street;

	private TextView phone;

	private TextView homepage;

	private TextView openingHours;

	private EditText notes;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail);

		Bundle bundle = this.getIntent().getExtras();
		String param1 = bundle.getString("pubName");

		MySQLiteHelper dbHelper = new MySQLiteHelper(this);
		pub = dbHelper.getPubByName(param1);

		name = (TextView) findViewById(R.id.name);
		name.setText(pub.getName());

		phone = (TextView) findViewById(R.id.phone);
		phone.setText(pub.getPhone());

		street = (TextView) findViewById(R.id.street);
		street.setText(pub.getStreet());

		homepage = (TextView) findViewById(R.id.homepage);
		homepage.setMovementMethod(LinkMovementMethod.getInstance());
		homepage.setText(pub.getHomepage());

		openingHours = (TextView) findViewById(R.id.openingHours);
		openingHours.setText(pub.getOpeningHours());

		notes = (EditText) findViewById(R.id.notes);
		notes.setText(pub.getNotes());

	}

	public void savePub(View v) {

		Toast t = Toast.makeText(this, "Saving data in progress",
				Toast.LENGTH_LONG);
		t.show();
		Intent myIntent = new Intent(this, SearchActivity.class);
		startActivity(myIntent);

		Pub changedPub = new Pub();
		name = (TextView) findViewById(R.id.name);
		notes = (EditText) findViewById(R.id.notes);

		changedPub.setName(name.getText().toString());
		changedPub.setNotes(notes.getText().toString());

		MySQLiteHelper dbHelper = new MySQLiteHelper(this);
		dbHelper.updatePub(changedPub);

	}

}
